package table_Mixage;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class TestCanal {
	static Canal c = new Canal(10,16000);
	
	@Before
	
	public void setUp() throws Exception {
		for( int i =0; i<10;i++)
			c.addEchantillon(i);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testGetEchantillon() {
		assertEquals(0,c.getEchantillon());
	}

	@Test
	public void testGetEchantillonInt() {
		assertEquals(0,c.getEchantillon(0));
	}

	@Test
	public void testGetNbech() {
		assertEquals(10,c.getNbech());
	}

	@Test
	public void testGetFragment() {
		c.createFragment(0, 1);
		assertEquals(1,c.getFragment(0).getDuree());
	}

	@Test
	public void testGetNbFragment() {
		Canal c1 = new Canal(16,16000);
		for (int i=0; i<16; i++)
			c1.addEchantillon(i);
		c1.createFragment(0, 1);
		assertEquals(1,c1.getNbFragment());
	}

	@Test
	public void testCanal() {
		Canal c1 = new Canal();
		for (int i=0; i<10000; i++)
				c1.addEchantillon(i);
		assertEquals(10000,c1.getNbech());
	}

	@Test
	public void testCanalLongInt() {
		Canal c1 = new Canal(16,16000);
		for (int i=0; i<16; i++)
			c1.addEchantillon(i);
		assertEquals(16,c1.getNbech());
	}

	@Test
	public void testCreateFragment() {
		int nb = c.createFragment(0, 1);
		assertEquals(0,c.getFragment(nb).getDateDebut());
	}

	@Test
	public void testRemoveFragment() {
		Canal c1 = new Canal(16,16000);
		for (int i=0; i<16; i++)
			c1.addEchantillon(i);
		c1.createFragment(0, 1);
		c1.removeFragment(0);
		assertEquals(0,c1.getNbFragment());
	}

	@Test
	public void testAddFragment() {
		Canal c1 = new Canal(16,16000);
		for (int i=0; i<16; i++)
			c1.addEchantillon(i);
		c1.createFragment(0, 1);
		c1.addFragment(c1.copier(0), 2,16000);
		assertEquals(1,c1.getNbFragment());
	}

	@Test
	public void testDeleteFragment() {
		Canal c1 = new Canal(10,16000);
		for (int i=0; i<10; i++)
			c1.addEchantillon(i);
		c1.createFragment(0, 3);
		c1.deleteFragment(0);
		assertEquals(7,c1.getNbech());
	}

	@Test
	public void testAjoutAuFragmentIntArrayFragment() {
		Canal c1 = new Canal(10,16000);
		for (int i=0; i<10; i++)
			c1.addEchantillon(i);
		c1.createFragment(1, 4);
		c1.ajoutAuFragment(c1.copier(0), 0);
		assertEquals(2,c1.getEchantillon(1));
		
	}

	@Test
	public void testAjoutAuFragmentIntInt() {
		Canal c1 = new Canal(10,16000);
		for (int i=0; i<10; i++)
			c1.addEchantillon(i);
		c1.createFragment(1, 4);
		c1.ajoutAuFragment(2,0 );
		assertEquals(3,c1.getEchantillon(1));
	}
	@Test
	public void testSynchronizeFrequenceUP() {
		Canal c1 = new Canal(10,16000);
		Canal c2 = new Canal(10,32000);
		for (int i=0; i<10; i++){
			c1.addEchantillon(i);
			c2.addEchantillon(i);}
		c1.synchronizeFrequence(32000);
		assertEquals(20,c1.getNbech());
	}
	public void testSynchronizeFrequenceDOWN() {
		Canal c1 = new Canal(10,16000);
		Canal c2 = new Canal(10,32000);
		for (int i=0; i<10; i++){
			c1.addEchantillon(i);
			c2.addEchantillon(i);}
		c2.synchronizeFrequence(16000);
		assertEquals(5,c2.getNbech());
	}
	@Test
	public void testToString() {
		Canal c1 = new Canal(10,16000);
		for (int i=0; i<10; i++)
			c1.addEchantillon(i);
		assertEquals(" Nombre d'échantillons du canal: 10 Nombre de Fragments: 0 Frequence: 16000",c1.toString());
	}

	@Test
	public void testEqualsCanal() {
		Canal c1 = new Canal(10,16000);
		for (int i=0; i<10; i++)
			c1.addEchantillon(i);
		assertEquals(true,c1.equals(c1));
	}

}
